package com.ssms.controller;

import com.ssms.commons.Result;
import com.ssms.commons.TablePage;
import com.ssms.model.Course;
import com.ssms.service.ClazzService;
import com.ssms.service.CourseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/course")
public class CourseController {

    @Resource
    private CourseService courseService;

    @RequestMapping()
    public String course() {
        return "course";
    }

    @RequestMapping("list")
    @ResponseBody
    public TablePage list(TablePage tablePage, @RequestParam(value = "subjectId") Integer subjectId) {
        return courseService.search(tablePage, subjectId);
    }

    @RequestMapping("all/{subjectId}")
    @ResponseBody
    public Result listOfSubject(@PathVariable("subjectId") Integer subjectId) {
        return courseService.getListBySubjectId(subjectId);
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(Course course) {
        return courseService.save(course);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(Course course) {
        return courseService.update(course);
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result delete(Integer id) {
        return courseService.delete(id);
    }

}
